class Product < ActiveRecord::Base
  attr_accessible :product_id, :description, :image_url, :price, :title, :category_id, :line_item_id, :promote
  
  validates :title, :description, :price, presence: true
  
  has_one :category
  has_many :line_items
  
  has_and_belongs_to_many :addons,
    :class_name => "Product",
    :association_foreign_key => "addon_id",
    :join_table => "addons_products"
  
  def chf_price
    
  end
  
  def euro_price
    euroToChf = CurrencyWebservice.new().get().to_f 
    chfToEuro = 1 / euroToChf
    #chfToEuro = (chfToEuro * 100).round / 100.0
    price * chfToEuro
  end
  
  def image
    image_url.empty? ? '/assets/books_logo.jpg' : image_url
  end
  
end
